<template>
  <div>
    <el-dialog
      :title="info.title"
      :visible.sync="info.isshow"
      @click="cancel"
      @close="close"
    >
      <el-form :model="formData" ref="formData" :rules="rules">
        <el-form-item label="属性名" prop="rolename" label-width="100px">
          <el-input v-model="formData.rolename"></el-input>
        </el-form-item>


        <el-form-item label="属性值" prop="rolename" label-width="100px" >
          <el-input v-model="formData.rolename"></el-input><el-button type="success">成功按钮</el-button>

          <el-input v-model="formData.rolename"></el-input><el-button type="success">成功按钮</el-button>
        </el-form-item>
        <el-form-item label="状态" prop="status" label-width="100px">
          <el-radio-group v-model="formData.status">
            <el-radio :label="1">正常</el-radio>
            <el-radio :label="2">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ["info"],
  data() {
    return {
      formData: {},

      rules: {
        rolename: [{ required: true, message: "请输入标题", trigger: "blur" }],
      },
      treeData: [],
      defaultProps: {
        children: "children",
        label: "title",
      },
    };
  },
  created() {
    this.gettreeData();
  },
  methods: {
    setValue(data) {
      this.formData = { ...data };
      let str = this.formData.menus;
      if (this.formData.menus) {
        this.formData.menus = str.split(",");
        this.$nextTick(() => {
          this.$refs.tree.setCheckedKeys(this.formData.menus);
        });
      }
    },
    gettreeData() {
      this.$http
        .get("menulist?istree=1")
        .then((res) => {
          this.treeData = res.list;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    submitForm() {
      // this.isshow = false;

      this.$refs.formData.validate((valid) => {
        this.formData.menus = this.$refs.tree.getCheckedKeys();
        let url = "";
        if (valid) {
          if (this.formData.id) {
            //有id是修改数据
            url = "/roleedit";
          } else {
            url = "/roleadd";
          }
          this.$http
            .post(url, this.formData)
            .then((res) => {
              console.log(res);
              if (res.list.code === 200) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                });
              }
              this.$emit("close");
              this.$emit("updata");
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("err");
          return false;
        }
      });
    },
    cancel() {
      //   this.isshow = false;
      this.$emit("close");
    },
    close() {
      //   this.isshow = false;
      this.formData.menus = [];
      this.$refs.tree.setCheckedKeys(this.formData.menus);
    },
    edit() {
      this.info.isshow = true;
      this.info.title = "修改菜单";
      let data = data;
    },
  },
};
</script>
<style>
</style>